// 同时发送请求的数量
let requestTimes = 0;
export const request = (params) =>{
    requestTimes++;
    // 准备请求头
    let header = {...params.header}
    if(params.url.includes("/my/")){
        header["Authorization"] = wx.getStorageSync('token')
        // console.log(header);   
    }
    wx.showLoading({
        title: "加载中",
        mask: true,
    });
    // 配置基准路径
    const baseUrl= "https://api.zbztb.cn/api/public/v1"
    return new Promise((resolve,reject) => {
        wx.request({
            ...params,
            header:header,
            url:baseUrl+params.url,
            success: (result) => {
                resolve(result)
            },
            fail: (err) => {
                reject(err)
            },
            complete: () =>{
                requestTimes--;
                // 关闭正在加载的图标
                if(requestTimes===0){
                  wx.hideLoading();
                }
            }
        })
    } )
}